package file.test;

import java.io.File;
import java.util.HashMap;
import java.util.function.BiConsumer;

/*
键盘录入文件夹路径，统计每种文件的个数并打印
 */
public class FileTest5 {
    static HashMap<String,Integer> hm =  new HashMap<>();
    static int count=0;
    public static void main(String[] args) {
        File dir = FileTest1.getDir();
        getFileNum(dir);
        hm.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String s, Integer integer) {
                System.out.println(s+"类型"+integer+"个");
            }
        });
    }
    public static void getFileNum(File dir){
        File[] files = dir.listFiles();
        for (File file : files) {
            if (file.isFile()) {
                String fileName = file.getName();
                if (fileName.contains(".")){
                    String[] sArr = fileName.split("\\.");
                    String type = sArr[sArr.length-1];
                    if (hm.containsKey(type)){
                        hm.put(type,hm.get(type)+1);
                    }else{
                        hm.put(type,1);
                    }
                }else{
                    count++;
                }
            }else {
               if (file.listFiles()!=null) {
                   getFileNum(file);
               }
            }
        }

    }
}
